#include "figure.h"
#include <GL/glut.h>
#include <stdio.h>
#include <vector>
#include <math.h>
#include "globals_.h"
#include <boost/random.hpp>

using namespace std;

boost::mt19937 generator((unsigned)time(NULL));

unsigned int rnd() {
    boost::uniform_int<> distribution(1, 10);
    boost::variate_generator<boost::mt19937&, boost::uniform_int<> > die(generator, distribution);
    return die();
}

Figure::Figure(){
	//HEIGHT = 100

	this->Vi = 0.0;
	this->_time = 0;
	this->going_up = false;

	this->h = HEIGHT;
	this->max_h = h;
}

Figure::~Figure(){}

Triangle::Triangle(Point center, float radio){
	this->center = center;
	this->radio = radio;

//	float tmp = (float)rnd()/10.0;
//	this->h = HEIGHT+ (HEIGHT*tmp);
//	this->max_h = h;

	this->option_draw = rnd();

	vecPoints.push_back(pair<float,float>(this->center.first+radio, this->center.second-radio));
	vecPoints.push_back(pair<float,float>(this->center.first,this->center.second+radio));
	vecPoints.push_back(pair<float,float>(this->center.first-radio,this->center.second-radio));
}

Triangle::~Triangle(){
}

void Triangle::draw(){

	glColor3f(0.5,0.5,0.5);

	glBegin(GL_TRIANGLES);
			glVertex2f(this->center.first+radio,this->center.second-radio);
			glVertex2f(this->center.first,this->center.second+radio);
			glVertex2f(this->center.first-radio,this->center.second-radio);
	glEnd();
}

void Triangle::updatePoints(){
//	cout<<"Size = "<<vecPoints.size()<<endl;
	vecPoints[0].first = this->center.first+radio;
	vecPoints[0].second = this->center.second-radio;

	vecPoints[1].first = this->center.first;
	vecPoints[1].second =this->center.second+radio;

	vecPoints[2].first = this->center.first-radio;
	vecPoints[2].second = this->center.second-radio;
}

/*------------------------   Rectangle  -----------------------------*/

Rectangle::Rectangle(Point center, float radio1){
	this->center = center;
	this->radio_min = this->radio_max = radio1;

	float tmp = (float)rnd()/10.0;
	this->h = HEIGHT+ (HEIGHT*tmp);
	this->max_h = h;

	vecPoints.push_back(pair<float,float>(center.first+radio_min,center.second-radio_max));
	vecPoints.push_back(pair<float,float>(center.first+radio_min,center.second+radio_max));
	vecPoints.push_back(pair<float,float>(center.first-radio_min,center.second+radio_max));
	vecPoints.push_back(pair<float,float>(center.first-radio_min,center.second-radio_max));
}

Rectangle::~Rectangle(){
}

void Rectangle::draw(){
	glColor3f(0.5,0.5,0.5);
	glBegin(GL_QUADS);
		glVertex2f(center.first+radio_min,center.second-radio_max);
		glVertex2f(center.first+radio_min,center.second+radio_max);
		glVertex2f(center.first-radio_min,center.second+radio_max);
		glVertex2f(center.first-radio_min,center.second-radio_max);
	glEnd();
}

void Rectangle::updatePoints(){
//	cout<<"Size = " <<vecPoints.size()<<endl;

	vecPoints[0].first = center.first+radio_min;
	vecPoints[0].second = center.second-radio_max;

	vecPoints[1].first = center.first+radio_min;
	vecPoints[1].second = center.second+radio_max;

	vecPoints[2].first = center.first-radio_min;
	vecPoints[2].second = center.second+radio_max;

	vecPoints[3].first = center.first-radio_min;
	vecPoints[3].second = center.second-radio_max;

//	cout<<vecPoints[0].first<<","<<vecPoints[0].second<<"\t"<<vecPoints[3].first<<","<<vecPoints[3].second<<endl;
}
